﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;

namespace NabNetLib
{
    public static class Logger
    {
        static Logger()
        {
            XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings[Constants.LOG_CONFIG_FILE_KEY]));
        }
        private static readonly ILog _log = LogManager.GetLogger("NabNet");

        public static void Log(string message,Exception ex)
        {
            Log(LogType.Error,message + Environment.NewLine + ex.ToString());
        }

        public static void Log(LogType type, string message)
        {
            switch (type)
            {
                case LogType.Debug:
                    if(_log.IsDebugEnabled) _log.Debug(message);
                    break;
                case LogType.Info:
                    if (_log.IsInfoEnabled) _log.Info(message);
                    break;
                case LogType.Warn:
                    if (_log.IsWarnEnabled) _log.Warn(message);
                    break;
                case LogType.Error:
                    if (_log.IsErrorEnabled) _log.Error(message);
                    break;
                case LogType.Fatal:
                    if (_log.IsFatalEnabled) _log.Fatal(message);
                    break;
            }
            
        }
    }

    public enum LogType
    {
        Debug,Info,Warn,Error,Fatal
    }
}
